package com.lanou3g.k12.web.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lanou3g.k12.entity.CourseType;
import com.lanou3g.k12.service.CourseLevelService;
import com.lanou3g.k12.utils.K12Result;
import com.lanou3g.k12.utils.K12ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class CourseLevelController {

    @Autowired
    CourseLevelService courseLevelService;

    // 查询等级信息
    @GetMapping("/courseLevels")
    public K12Result findAll(@RequestParam(value = "page",defaultValue = "1") Integer page,@RequestParam(value = "size",defaultValue = "30") Integer size){
        Page<Object> objects = PageHelper.startPage(page, size);
        courseLevelService.findAll();

        return K12ResultUtils.ok(objects);
    }


    // 根据等级查询分类，书籍
    @GetMapping("/courses/level/{id}")
    public K12Result findCoursesByLevel(@PathVariable Long id){

       List<CourseType>  courses = courseLevelService.findCoursesByLevel(id);
       return K12ResultUtils.ok(courses);
    }


    // 根据等级查询分类，书籍(后端)
    @GetMapping("/courses/level/backend/{id}")
    public K12Result findByLevelForBackEnd(@PathVariable Long id){
        List<CourseType> courses = courseLevelService.findByLevelForBackEnd(id);
        return K12ResultUtils.ok(courses);
    }


}
